package br.com.jspl.app.ui;

import java.awt.event.ActionEvent;
import java.io.File;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.Icon;
import javax.swing.JFileChooser;

public class ArquivosAction extends AbstractAction {
	/**
	 * 
	 */
	private static final long serialVersionUID = -6149967392431257189L;
	int tipo;
	FileChoose fileC;
	
	public ArquivosAction(String nome, Icon icone,int t,FileChoose f) {
		putValue(Action.NAME,nome);
		putValue(Action.SMALL_ICON ,icone);
		tipo =t;	
		fileC=f;
	}
	
	public void actionPerformed(ActionEvent evt) {
		JFileChooser fc;
		fc= (fileC.getFc());
		if (tipo == 1) {
			int returnVal = fc.showOpenDialog(fileC.getProtoboard());
			if (returnVal == JFileChooser.APPROVE_OPTION) {
				File f =fc.getSelectedFile();
				fileC.setFile(f);
				fileC.Abrir();
            	/*if  (fc.getSelectedFile() == null)
            	{
            		fileC.setFile(f);              
            		JOptionPane.showMessageDialog(fileC.getProtoboard(),"No foi possvel abrir o arquivo.:"+ fc.getName());
            	*/
			}
		} 
		else {
			int returnVal = fc.showSaveDialog(fileC.getProtoboard());
			if (returnVal == JFileChooser.APPROVE_OPTION) {
				File f =fc.getSelectedFile();
				fileC.setFile(f);
				fileC.Salvar();
				//This is where a real application would save the file.
			}
		}
	}
}
